package com.tledu.spring.core.likou;

/**
 * @author Lsj
 * @version 1.0
 * @date 2021/7/7 11:41
 */
public class BigMealCount {
    public static void main(String[] args) {
        int[] deliciousness = {1, 3, 5, 7, 9};
        Solution solution = new Solution();
        System.out.println(solution.countPairs(deliciousness));
    }
}

/**
 * 这种方法超出了时间限制
 */
class Solution1 {
    public int countPairs(int[] deliciouseness) {
        int num = 0;
        for (int i = 0; i < deliciouseness.length; i++) {
            for (int j = i + 1; j < deliciouseness.length; j++) {
                String str = Integer.toBinaryString(deliciouseness[i] + deliciouseness[j]);
                if (str.lastIndexOf("1") == 0) {
                    System.out.println(deliciouseness[i] + ":" + deliciouseness[j]);
                    num++;
                }
            }
        }
        return num;
    }
}

class Solution {
    public int countPairs(int[] deliciousness) {
        int num = 0;
        for (int i = 0; i < deliciousness.length; i++) {
            for (int j = i + 1; j < deliciousness.length; j++) {
                int and = deliciousness[i] + deliciousness[j];
                String str = Integer.toBinaryString(and);
                if (str.lastIndexOf("1") == 0) {
                    num++;
                }
            }
        }
        return num;
    }
}
